<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>管理员登录</title>
    <base href="/qiandao/admin">
</head>
<body>
<div style="width: 250px;margin: 30px auto;">
    <div style="width: 100%">
        <span>账号：</span>
        <input type="text" name="username" value="admin"/>
    </div>
    <div style="width: 100%;margin-top: 15px">
        <span>密码：</span>
        <input type="password" name="password" value="admin"/>
    </div>
    <div style="margin-top: 15px">
        <button onclick="adminLogin()">确定</button>
    </div>
</div>
<script type="text/javascript">
    function adminLogin() {
        var username = document.getElementsByName("username")[0].value;
        var password = document.getElementsByName("password")[0].value;
        console.log("username", username);
        console.log("password", password);
        fetch("/qiandao/admin/login", {
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json'
            },
            method: "POST",
            body: JSON.stringify({username: username, password: password})
        }).then(function (response) {
            if (!response.ok) {
                alert(response.status + ": 服务器错误，请稍后再试！")
            } else {
                var result = response.json();
                result.then(function (res) {
                    console.log("res", res.href);
                    location.href = res.href
                });
            }
        })
    }
</script>
</body>
</html>